﻿
Imports NewHeaderSystems.Archive.Engine

Public Class PageTemplate
    Inherits Microsoft.Samples.Windows.Forms.Navigation.Page

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        SetBackgroundTransparentOn(lblMasterTitle)
        SetBackgroundTransparentOn(lblMasterDescription)
        SetBackgroundTransparentOn(picMaster)
        Me.ScrollBars = Windows.Forms.ScrollBars.None

    End Sub

    Private Sub SetBackgroundTransparentOn(ByVal ctrl As Control)
        pnlBanner.Controls.Add(ctrl)
        ctrl.BackColor = Color.FromArgb(0, lblMasterTitle.BackColor)
    End Sub
    Public Property Title() As String
        Get
            Return lblMasterTitle.Text
        End Get
        Set(ByVal value As String)
            lblMasterTitle.Text = value
        End Set
    End Property

    Public Property Description() As String
        Get
            Return lblMasterDescription.Text
        End Get
        Set(ByVal value As String)
            lblMasterDescription.Text = value
        End Set
    End Property

    Public Property PageIcon() As Image
        Get
            Return picMaster.Image
        End Get
        Set(ByVal value As Image)
            picMaster.Image = value
        End Set
    End Property

    Protected Sub GoToPage(ByVal formType As FormTypes)
        Select Case formType
            Case FormTypes.Home
                Go(GetType(Home))
            Case FormTypes.Search
                Go(GetType(Search))
            Case FormTypes.StartArchiving
                GoToPageStartArchiving()
            Case FormTypes.FinishArchiving
                Go(GetType(FinishArchiving))
            Case FormTypes.SystemSettings
                Go(GetType(SystemAdministration))
            Case FormTypes.Administration
                Go(GetType(Administration))
            Case FormTypes.ArchiveHistory
                Go(GetType(ArchiveHistory))
            Case FormTypes.AccountMaintenance
                Go(GetType(AccountMaintenance))
            Case FormTypes.SecurityMaintenance
                Go(GetType(SecurityMaintenance))
            Case FormTypes.DownloadConfirms
                Go(GetType(DownloadConfirms))
        End Select
    End Sub

    Private Sub GoToPageStartArchiving()
        Dim archiveFileList = Processor.GetArchiveFileSet()
        Dim haveFilesToDownload As Boolean = (archiveFileList.Count <> 0)

        If Not haveFilesToDownload Then
            If SystemSettings.Instance.IsAplEnabled Then
                If DialogResult.Yes = MessageBox.Show("Download from Server?" + Environment.NewLine + "There are no files available for archiving, do you want to try downloading confirms from the server?", "Download from Server", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) Then
                    GoToPage(FormTypes.DownloadConfirms)
                End If
            Else
                MessageBox.Show("There are no files available for archiving.", "No Files Available", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)
            End If
        Else
            Go(GetType(StartArchiving))
        End If
    End Sub

    Protected Sub GoToFinishArchiving(ByVal archiveHistoryList As List(Of String))
        FinishArchiving.ArchiveHistoryList = archiveHistoryList
        Go(GetType(FinishArchiving))
    End Sub
End Class
